package com.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * Created by Mikey on 2017/4/21.
 */
@Controller
public class MainController {

    @RequestMapping(value = "/" , method = RequestMethod.GET)
    public String index(){

        return "index";
    }

    @RequestMapping(value = "/getData.json" , method = RequestMethod.GET)
    @ResponseBody
    public Map getData(){
        Map<String,List<Integer>> map = new HashMap<>();
        List<Integer> list_1 = new ArrayList<>();
        List<Integer> list_2 = new ArrayList<>();
        Random r = new Random();
        for(int i = 0; i < 100; i++){
            list_1.add(i);
            list_2.add(r.nextInt(100));
        }
        map.put("x",list_1);
        map.put("y",list_2);
        return map;
    }

    @RequestMapping(value = "/uploadFile.json" , method = RequestMethod.POST)
    @ResponseBody
    public String uploadFile(HttpServletRequest request, HttpServletResponse response){
        MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
        Iterator<String> fileName = multipartHttpServletRequest.getFileNames();
        System.out.println(fileName);
        return "";
    }
}
